package com.lzh.java9;

import org.junit.Test;

/**
 * @author liuzhihao
 * @create 2021-02-15 16:46
 */
public class StringTest {
    /**
     * 模拟一个trim方法，去除字符串两端的空格。
     */
    @Test
    public void test1(){

        String s = "  a  bc  ";

        int start = 0;
        int end = s.length() - 1;

        while(start <=end && s.charAt(start) ==' '){
            start++;
        }
        while(start <= end && s.charAt(end-1) == ' '){
            end--;
        }
        s = s.substring(start,end+1);
        System.out.println(s+"==="+s.length());


    }

}
